home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cmouse.zip / MOUSE.I < prev    next >
Text File  |  1988-03-22  |  8KB  |  204 lines

  1. /* MOUSE.INC: Turbo C Source code for mouse interface functions.   */
  2. /*    Must #include dos.h before this #include to define the       */
  3. /*    register set used to pass args to device driver              */
  4. /* --------------------------------------------------------------- */
  5. /* Define int for mouse device driver */
  6. #define  callMDD int86(0x33, &inreg, &outreg)
  7.  
  8. /* Define sorting macros used locally */
  9. #define  lower (x, y)  (x < y) ? x : y
  10. #define  upper (x, y)  (x > y) ? x : y
  11.  
  12. /* STATIC REGISTERS USED THROUGHOUT */
  13. union REGS  inreg, outreg;
  14.  
  15. /* STRUCTURES USED BY THESE FUNCTIONS */
  16. typedef struct {
  17.   int exists,                           /* TRUE if mouse is present */
  18.       nButtons;                           /* # of buttons on mouse */
  19. } resetRec;                                  /* returned by mReset */
  20.  
  21. typedef struct {
  22.   int buttonStatus,       /* bits 0-2 on if corresp button is down */
  23.       opCount,                  /* # times button has been clicked */
  24.       column, row;                                     /* position */
  25. } locRec;                 /* returned by mPos, mPressed, mReleased */
  26.  
  27. typedef struct {
  28.   int hCount,                           /* net horizontal movement */
  29.   vCount;                                 /* net vertical movement */
  30. } moveRec;                                  /* returned by mMotion */
  31. /* --------------------------------------------------------------- */
  32. /* Following are implementations of the Microsoft mouse functions  */
  33.  
  34. resetRec *mReset ()
  35. /* Resets mouse to default state. Returns pointer to a structure   */
  36. /* indicating whether or not mouse is installed and, if so, how    */
  37. /* many buttons it has.                                            */
  38. /* Always call this function during program initialization.        */
  39. {
  40. static resetRec  m;
  41.  
  42.   inreg.x.ax = 0;                                    /* function 0 */
  43.   callMDD;
  44.   m.exists = outreg.x.ax;
  45.   m.nButtons = outreg.x.bx;
  46.   return ( &m );
  47. } /* ------------------------ */
  48. void mShow (void)
  49. /* Makes the mouse cursor visible. Don't call if cursor is already */
  50. /* visible, and alternate with calls to mHide.                     */
  51. {
  52.   inreg.x.ax = 1;                                    /* function 1 */
  53.   callMDD;
  54. } /* ------------------------ */
  55. void mHide (void)
  56. /* Makes mouse cursor invisible. Movement and button activity are  */
  57. /* still tracked. Do not call if cursor is already hidden, and     */
  58. /* alternate with calls to mShow                                   */
  59. {
  60.   inreg.x.ax = 2;                                    /* function 2 */
  61.   callMDD;
  62. } /* ------------------------ */
  63. locRec *mPos (void)
  64. /* Gets mouse cursor position and button status, returns pointer   */
  65. /* to structure containing this info                               */
  66. {
  67. static locRec  m;
  68.  
  69.   inreg.x.ax = 3;                                    /* function 3 */
  70.   callMDD;
  71.   m.buttonStatus = outreg.x.bx;                   /* button status */
  72.   m.column = outreg.x.cx;                        /* horiz position */
  73.   m.row = outreg.x.dx;                            /* vert position */
  74.   return (&m);
  75. } /* ------------------------ */
  76. void  mMoveto (int newCol, int newRow)
  77. /* Move mouse cursor to new position */
  78. {
  79.   inreg.x.ax = 4;                                    /* function 4 */
  80.   inreg.x.cx = newCol;
  81.   inreg.x.dx = newRow;
  82.   callMDD;
  83. } /* ------------------------ */
  84. locRec  *mPressed (int button)
  85. /* Gets pressed info about named button: current status (up/down), */
  86. /* times pressed since last call, position at most recent press.   */
  87. /* Resets count and position info. Button 0 is left, 1 is right on */
  88. /* Microsoft mouse.                                                */
  89. /* Returns pointer to locRec structure containing info.            */
  90. {
  91. static locRec  m;
  92.  
  93.   inreg.x.ax = 5;                                    /* function 5 */
  94.   inreg.x.bx = button;              /* request for specific button */
  95.   callMDD;
  96.   m.buttonStatus = outreg.x.ax;
  97.   m.opCount = outreg.x.bx;
  98.   m.column  = outreg.x.cx;
  99.   m.row     = outreg.x.dx;
  100.   return (&m);
  101. } /* ------------------------ */
  102. locRec  *mReleased (int button)
  103. /* Same as mPressed, except gets released info about button */
  104. {
  105. static locRec  m;
  106.  
  107.   inreg.x.ax = 6;                                    /* function 6 */
  108.   inreg.x.bx = button;              /* request for specific button */
  109.   callMDD;
  110.   m.buttonStatus = outreg.x.ax;
  111.   m.opCount = outreg.x.bx;
  112.   m.column  = outreg.x.cx;
  113.   m.row     = outreg.x.dx;
  114.   return (&m);
  115. } /* ------------------------ */
  116. void  mColRange (int hmin, int hmax)
  117. /* Sets min and max horizontal range for mouse cursor. Moves   */
  118. /* cursor inside range if outside when called. Swaps values if */
  119. /* hmin and hmax are reversed.                                 */
  120. {
  121.   inreg.x.ax = 7;                                /* function 7 */
  122.   inreg.x.cx = hmin;
  123.   inreg.x.dx = hmax;
  124.   callMDD;
  125. } /* ------------------------ */
  126. void  mRowRange (int vmin, int vmax)
  127. /* Same as mHminmax, except sets vertical boundaries. */
  128. {
  129.   inreg.x.ax = 8;                                    /* function 8 */
  130.   inreg.x.cx = vmin;
  131.   inreg.x.dx = vmax;
  132.   callMDD;
  133. } /* ------------------------ */
  134. void  mGraphCursor (int hHot, int vHot, unsigned maskSeg,
  135.                     unsigned maskOfs)
  136. /* Sets graphic cursor shape */
  137. {
  138. struct SREGS  seg;
  139.  
  140.   inreg.x.ax = 9;                                    /* function 9 */
  141.   inreg.x.bx = hHot;                /* cursor hot spot: horizontal */
  142.   inreg.x.cx = vHot;                  /* cursor hot spot: vertical */
  143.   inreg.x.dx = maskOfs;
  144.   seg.es = maskSeg;
  145.   int86x (0x33, &inreg, &outreg, &seg);
  146. } /* ------------------------ */
  147. void  mTextCursor (int curstype, unsigned arg1, unsigned arg2)
  148. /* Sets text cursor type, where 0 = software and 1 = hardware)     */
  149. /* For software cursor, arg1 and arg2 are the screen and cursor    */
  150. /*   masks.                                                        */
  151. /* For hardware cursor, arg1 and arg2 specify scan line start/stop */
  152. /*   i.e. cursor shape.                                            */
  153. {
  154.   inreg.x.ax = 10;                                  /* function 10 */
  155.   inreg.x.bx = curstype;
  156.   inreg.x.cx = arg1;
  157.   inreg.x.dx = arg2;
  158.   callMDD;
  159. } /* ------------------------ */
  160. moveRec  *mMotion (void)
  161. /* Reports net motion of cursor since last call to this function   */
  162. {
  163. static moveRec  m;
  164.  
  165.   inreg.x.ax = 11;                                  /* function 11 */
  166.   callMDD;
  167.   m.hCount = _CX;                                /* net horizontal */
  168.   m.vCount = _DX;                                  /* net vertical */
  169.   return (&m);
  170. } /* ------------------------ */
  171. void mInstTask (unsigned mask, unsigned taskSeg, unsigned taskOfs)
  172. /* Installs a user-defined task to be executed upon one or more    */
  173. /*   mouse events specified by mask.                               */
  174. {
  175. struct SREGS  seg;
  176.  
  177.   inreg.x.ax = 12;                                  /* function 12 */
  178.   inreg.x.cx = mask;
  179.   inreg.x.dx = taskOfs;
  180.   seg.es = taskSeg;
  181.   int86x (0x33, &inreg, &outreg, &seg);
  182. } /* ------------------------ */
  183. void mLpenOn (void)
  184. /* Turns on light pen emulation. This is the default condition.    */
  185. {
  186.   inreg.x.ax = 13;                                  /* function 13 */
  187.   callMDD;
  188. } /* ------------------------ */
  189. void mLpenOff (void)
  190. /* Turns off light pen emulation. */
  191. {
  192.   inreg.x.ax = 14;                                  /* function 14 */
  193.   callMDD;
  194. } /* ------------------------ */
  195. void mRatio (int horiz, int vert)
  196. /* Sets mickey-to-pixel ratio, where ratio is R/8. Default is 16   */
  197. /*   for vertical, 8 for horizontal */
  198. {
  199.   inreg.x.ax = 15;                                  /* function 15 */
  200.   inreg.x.cx = horiz;
  201.   inreg.x.dx = vert;
  202.   callMDD;
  203. } /* ------------------------ */
  204.